using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Tickets;

namespace AndyPike.Unfuddle.Commands.Tickets
{
    /// <summary>
    /// Provides a command for deleting an existing ticket from the Unfuddle server
    /// </summary>
    public class DeleteTicket : IUnfuddleChangeCommand
    {
        private readonly int projectId;
        private readonly int ticketId;

        /// <summary>
        /// Instantiates the DeleteTicket command
        /// </summary>
        /// <param name="projectId">The id of the project that owns the ticket to delete</param>
        /// <param name="ticketId">The id of the existing ticket to delete</param>
        public DeleteTicket(int projectId, int ticketId)
        {
            GuardAgainst.ArgumentOutsideRange(projectId, "projectId", 1, int.MaxValue);
            GuardAgainst.ArgumentOutsideRange(ticketId, "ticketId", 1, int.MaxValue);

            this.projectId = projectId;
            this.ticketId = ticketId;
        }

        /// <summary>
        /// Deletes an existing ticket from the Unfuddle server
        /// </summary>
        /// <param name="service">The Unfuddle service to use when executing the command</param>
        public void Execute(IUnfuddleService service)
        {
            GuardAgainst.ArgumentNull(service, "service");

            string url = service.BuildUrl("projects/{0}/tickets/{1}", projectId, ticketId);
            service.InvokeRequest<Ticket>(url, HttpMethod.DELETE, null);
        }
    }
}